﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using WWF.Contracts;
using WWF.Data;

namespace WWF.Activities
{

    public sealed class UpdateApplicationStatus : CodeActivity
    {
        // Define an activity input argument of type string
        public InArgument<ApplicationResponse> ApplicationResponseRequest { get; set; }
        public InArgument<string> StatusRequest { get; set; }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            ApplicationResponse applicationResponse = context.GetValue(ApplicationResponseRequest);
            string status = context.GetValue(StatusRequest);
            using (UniversityApplicationEntities entity = new UniversityApplicationEntities())
            {
                var query = from a in entity.Applications
                            where a.ApplicationID == applicationResponse.ApplicationID
                            select a;
                Application app = query.FirstOrDefault();
                app.Status = status;
                entity.SaveChanges();
            }
        }
    }
}
